<?php

namespace App\Http\Controllers\Note;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use QL\QueryList;
use Illuminate\Support\Facades\Storage;

class QueryListController extends Controller
{
    public function query(Request $request)
    {
        if($request->input('cache')){
            $path = 'html/' . md5($request->input('url')) . '.html';
            $html = file_get_contents($path);
            if (!$html){
                $html = QueryList::get($request->input('url'));
                dd($html);
                Storage::disk('public')->put($path, $html);
            }
        }
        $rules = $request->input('rule');
        $rt = QueryList::html($html)->rules($rules)->query()->getData();
        return $this->response($rt->all());
    }
}
